/*
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-08-28 14:39:14
 * @LastEditors: xuwejie 1529315455@qq.com
 * @LastEditTime: 2023-11-22 09:12:38
 * @FilePath: \v9\src\utils\debounce.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 防抖
export const debounce = (fn, time) => {
  time = time || 200
  // 定时器
  let timer = null
  return function (...args) {
    var _this = this
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(function () {
      timer = null
      fn.apply(_this, args)
    }, time)
  }
}
// 节流
export const throttle = (fn, time) => {
  let timer = null
  time = time || 1000
  return function (...args) {
    if (timer) {
      return
    }
    const _this = this
    timer = setTimeout(() => {
      timer = null
    }, time)
    fn.apply(_this, args)
  }
}